package cn.woniu.ecommerceplatform.controller;

import cn.woniu.ecommerceplatform.entity.CountPointMessage;
import cn.woniu.ecommerceplatform.entity.Customer;
import cn.woniu.ecommerceplatform.entity.QueryCustomer;
import cn.woniu.ecommerceplatform.service.CustomerService;
import cn.woniu.ecommerceplatform.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired(required = false)
    private CustomerService service;
    @PostMapping("/queryCustomer")
    public ResponseResult<?> queryList(@RequestBody QueryCustomer q){
        return service.queryCustomList(q.getPhone(),q.getName(),q.getLevel(),q.getPageNo(),q.getPageSize(),q.getPageCount(),q.getOrderBy());
    }
    @PostMapping("/insertCustomer")
    public ResponseResult insertCustomer(@RequestBody Customer customer){
        return service.insertCustomer(customer);
    }

    /**
     * 更新会员信息:修改昵称,修改等级,修改电话,修改备注
     * @return
     */
    @PostMapping("/updateCustomer")
    public ResponseResult updateCustomer(@RequestBody Customer customer){
        return service.updateCustomer(customer);
    }
    @RequestMapping("/deleteCustomer")
    public ResponseResult deleteCustomerById(Integer id){
        return service.deleteCustomer(id);
    }

    /**
     * 移入黑名单
     */
    @RequestMapping("/insertBlackList")
    public ResponseResult insertBlackList(String account){
        return service.insertBlackList(account);
    }

    /**
     * 根据account查询会员信息
     */
    @RequestMapping("/selectByAccount")
    public ResponseResult selectByAccount(String account){ return service.selectByAccount(account);}

    @PostMapping("/countPoint")
    public ResponseResult countPoint(@RequestBody CountPointMessage message){
        return service.countPoint(message.getAddress(),message.getOrders(),message.getPointNeed());
    }

    /**
     * 注册验证account是否唯一
     * @param account
     * @return
     */
    @RequestMapping("/queryAccount")
    public ResponseResult<?> queryAccount(String account){
        return service.queryAccount(account);
    }

    @RequestMapping("/insertRegister")
    public ResponseResult<?> insertRegister(String name,String phone,String account,String password){
        return service.insertRegister(name,phone,account,password);
    }

    @RequestMapping("/queryIdByAccount")
    public ResponseResult<?> queryIdByAccount(String account){
        return service.queryIdByAccount(account);
    }
    @RequestMapping("/addPoint")
    public ResponseResult<?> addPoint(String account,Double actualPay){
        return service.addPoint(account,actualPay);
    }

    /**
     * 会员查询自己的可显示信息
     * @param account
     * @return
     */
    @RequestMapping("/selectMyself")
    public ResponseResult<?> selectMyself(String account){
        return service.selectMyself(account);
    }

    /**
     * 会员通过id修改自己的信息
     * @param customer
     * @return
     */
    @PostMapping("/updateCustomByIdtMy")
    public ResponseResult<?> updateCustomByAccountMy(@RequestBody Customer customer){
        return service.updateCustomByAccountMy(customer);
    }
}
